{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pregnants_log</th>\n",
       "      <th>Plasma_glucose_concentration_log</th>\n",
       "      <th>blood_pressure_log</th>\n",
       "      <th>Triceps_skin_fold_thickness_log</th>\n",
       "      <th>serum_insulin_log</th>\n",
       "      <th>BMI_log</th>\n",
       "      <th>Diabetes_pedigree_function_log</th>\n",
       "      <th>Age_log</th>\n",
       "      <th>Target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.726987</td>\n",
       "      <td>0.723606</td>\n",
       "      <td>0.185978</td>\n",
       "      <td>0.641268</td>\n",
       "      <td>-0.921785</td>\n",
       "      <td>0.313496</td>\n",
       "      <td>0.683023</td>\n",
       "      <td>1.090723</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.611777</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.192353</td>\n",
       "      <td>0.201926</td>\n",
       "      <td>-0.921785</td>\n",
       "      <td>-1.048172</td>\n",
       "      <td>0.003389</td>\n",
       "      <td>0.218194</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.033509</td>\n",
       "      <td>1.139087</td>\n",
       "      <td>-0.350496</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.921785</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.754768</td>\n",
       "      <td>0.297648</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.611777</td>\n",
       "      <td>-5.470782</td>\n",
       "      <td>-0.192353</td>\n",
       "      <td>-0.362024</td>\n",
       "      <td>0.593035</td>\n",
       "      <td>-0.568138</td>\n",
       "      <td>-1.683477</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.539599</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.641268</td>\n",
       "      <td>1.121428</td>\n",
       "      <td>1.019098</td>\n",
       "      <td>1.886918</td>\n",
       "      <td>0.369875</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pregnants_log  Plasma_glucose_concentration_log  blood_pressure_log  \\\n",
       "0       0.726987                          0.723606            0.185978   \n",
       "1      -1.611777                          0.000000           -0.192353   \n",
       "2       1.033509                          1.139087           -0.350496   \n",
       "3      -1.611777                         -5.470782           -0.192353   \n",
       "4       0.000000                          0.539599            0.000000   \n",
       "\n",
       "   Triceps_skin_fold_thickness_log  serum_insulin_log   BMI_log  \\\n",
       "0                         0.641268          -0.921785  0.313496   \n",
       "1                         0.201926          -0.921785 -1.048172   \n",
       "2                         0.000000          -0.921785  0.000000   \n",
       "3                        -0.362024           0.593035 -0.568138   \n",
       "4                         0.641268           1.121428  1.019098   \n",
       "\n",
       "   Diabetes_pedigree_function_log   Age_log  Target  \n",
       "0                        0.683023  1.090723       1  \n",
       "1                        0.003389  0.218194       0  \n",
       "2                        0.754768  0.297648       1  \n",
       "3                       -1.683477  0.000000       0  \n",
       "4                        1.886918  0.369875       1  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.read_csv(\"./data/FE_diabetes-log.csv\")\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train = train['Target']   \n",
    "X_train = train.drop([\"Target\"], axis=1)\n",
    "\n",
    "feat_names = X_train.columns \n",
    "\n",
    "from scipy.sparse import csr_matrix\n",
    "X_train = csr_matrix(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('accuracy of each fold is: ', array([0.75324675, 0.72727273, 0.74675325, 0.78431373, 0.75163399]))\n",
      "('cv accuracy is:', 0.7526440879382056)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import cross_val_score\n",
    "loss = cross_val_score(lr, X_train, y_train, cv=5, scoring='accuracy')\n",
    "print ('accuracy of each fold is: ',loss)\n",
    "print ('cv accuracy is:', loss.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=5, error_score='raise-deprecating',\n",
       "       estimator=LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='warn',\n",
       "          n_jobs=None, penalty='l2', random_state=None, solver='liblinear',\n",
       "          tol=0.0001, verbose=0, warm_start=False),\n",
       "       fit_params=None, iid='warn', n_jobs=4,\n",
       "       param_grid={'penalty': ['l1', 'l2'], 'C': [0.1, 1, 10, 100, 1000]},\n",
       "       pre_dispatch='2*n_jobs', refit=True, return_train_score='warn',\n",
       "       scoring='accuracy', verbose=0)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "penaltys = ['l1','l2']\n",
    "Cs = [ 0.1, 1, 10, 100, 1000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "\n",
    "lr_penalty= LogisticRegression(solver='liblinear')\n",
    "grid= GridSearchCV(lr_penalty, tuned_parameters,cv=5, scoring='accuracy',n_jobs = 4,)\n",
    "grid.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.7591145833333334\n",
      "{'penalty': 'l1', 'C': 0.1}\n"
     ]
    }
   ],
   "source": [
    "# examine the best model\n",
    "print(grid.best_score_)\n",
    "print(grid.best_params_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAAEKCAYAAAA1qaOTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3Xt8VfWZ7/HPkzuBACFBRC6N3GoV5GJUFPSI2upgR8EL6BSltpTpGZ3p+Jr21Kk9rbbTjp5z7MzpaWe80FE6OqK1ogxTb1CvWLXIRfBSQUUFucmd3JP9nD/WStgJO8lOsvbeCfm+X6/12uvyW3s/e0Hy5HdZv2XujoiISFdlZToAERE5NiihiIhIJJRQREQkEkooIiISCSUUERG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r0aFatWsWNN97IM888w2233cbzzz/PkCFD2L9/P3369OEHP/gBGzdu5J//+Z9THpcSiohID7J//35effVVrrjiyN0S9fX1AEybNo3rrruOq666issvvzztsSmhiEivk2xNorFm8vBfnpXKcDrE3SktLU3Yp3Lvvffy2muvsXz5cqZMmcLatWvTGpv6UEREepDi4mKGDh3K0qVLAYjFYqxfvx6ADz74gKlTp/LjH/+Y4uJitm3bRlFREYcOHUpLbEooIhn29vaDTW310r4z77uCM+9rdXKMHuOcc87hqquuYuXKlQwfPpynn366/ZNCS5Ys4a677mLixImccsopLF++HICbbrqJCRMmMGHCBGbMmMH48eMZPrGM1954ncmTJ6tTXkTkWHH48OGm9Zdeeimpc8rKyti4cWOzfaNGjUqYgJYtW3bUvkGlJfxmxVK+UDqmg9F2nBKKiEgrulPfSU+gJi8REYmEEoqIiERCCUVERCKhhCKR02SaIr2TEoqISGvuuyRYJClKKCIiaZLu6euXLl3Kr35xb5fjTpaGDYuIZEBU09fX19eTk5P4V/ns2bM56ZwJ0QScBNVQREQyoCvT10+fPp2bbrqJ8vJyfvGLX/DEE09w5plnMnnyZL70pS+xa9cuABYtWsQ/3vIPAMybN49vfetbnH322YwaNapp6pYoqYaSBE2LIXKMefJm2LGh/XI73gxek+lHOX4C/NntXYurAxoaGli9ejUA+/bt49JLL8XMuOuuu7jzzju54447jjpn165drFq1ig0bNjBnzhxmz54daUxKKCIiPdDcuXOb1j/++GPmzJnDjh07qKmpYdy4cQnPmTVrFmbGqaeeyrZt2yKPSQlFRHqfZGsSjTWT6/8rdbF0Ut++fZvWb7jhBr73ve8xc+ZMVqxYwe23J/5++fn5TevuHnlM6kMREenhDhw4wLBhw3B3Fi9enLE4lFBERDKgK9PXt3Trrbcye/ZsTj/9dIYMGRJhlB2jJi8RkTSJavr6l19+udn2FVdc0eyRwI0WLFjAtFnnAfDAAw+0GktUlFBERFrTDftOujM1eYmISCSUUEREJBJKKCIiEgklFBERiYQ65SVymqpGjhWNz/W57+L7MhxJz6Aai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xOpSGJKKCIpEN65/b/NbKOZbTCzueH+rHAajncteJ7N78zsyvC0rxDOfGBmo4Ezge+7ewzA3T909/8Kyz4elhfpNlRlFkmNy4FJwESgFPijmb1IMA1OGXAycBzBlC//Fp4zjeCudYBTgHUeTPaXyEbg9JRELtJJqqGIpMZ0gtmMG9x9J/ACQQKYDvzG3WPuvoNg2pdGQ4Hdybx5mGhqzawo4rhFOk0JRaT7qCKYawmCeaAmmll2G+XzgeqURyWSJCUUkdR4CZgbPvBoMMFjdl8HVhE82CvLzIYQPCq20TvAGAAPnl2zGrgtbtbaMjO7JFwvAT5z97p0fSGR9iihiKTGUoJZX9cDvwf+R9jE9VuCGX3fBh4geBDTgfCc/6J5gllA8ETOzWa2EbifI8+/mRGWF+k2NNuwSJqZWT8PnuRXQlBrmebuO8JnWDwXbrfWGd/4Ho8BN7v7e2kIWSQpGuUlkn7Lwwch5QE/DmsuuHuVmf2Q4LnfH7d2cvjQsMeVTKS7UQ1FREQioT4UERGJhBKKiIhEQglFREQioYQiIiKRUEIREZFIKKGIiEgk/j8xZrwhVJmjWgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot CV误差曲线\n",
    "test_means = grid.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = grid.cv_results_[ 'std_test_score' ]\n",
    "train_means = grid.cv_results_[ 'mean_train_score' ]\n",
    "train_stds = grid.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'accuracy' )\n",
    "plt.savefig('LogisticGridSearchCV_C.png' )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cPickle\n",
    "\n",
    "cPickle.dump(grid.best_estimator_, open(\"L2_log_accracy.pkl\", 'wb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
